package cn.ronghuanet.auth.controller;

import cn.ronghuanet.auth.annotation.RonghuanetPermission;
import cn.ronghuanet.auth.domain.Permission;
import cn.ronghuanet.auth.query.PermissionQuery;
import cn.ronghuanet.auth.service.IPermissionService;
import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
@RonghuanetPermission(name="权限管理")
public class PermissionController {
    @Autowired
    private IPermissionService service;

    @PutMapping
    @RonghuanetPermission(name = "权限分页",desc = "权限分页")
    public AjaxResult getPermission(@RequestBody PermissionQuery permissionQuery){
        try {
            PageInfo<Permission> page = service.pageList(permissionQuery);
            return AjaxResult.success(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error();
    }

    /**
     * 获取所有的一级权限和对应的二级权限
     * @return
     */
    @GetMapping
    @RonghuanetPermission(name="查询权限",desc = "查询一级权限对应的二级权限")
    public AjaxResult getAllPermission(){
        try {
           List<Permission> list = service.getAllPermission();
           return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
    /**
     * 获取所有的一级权限和对应的二级权限
     * @return
     */
    @GetMapping("/sns")
    @RonghuanetPermission(name="查询权限",desc = "查询一级权限对应的二级权限")
    public AjaxResult getAllPermissionsns(){
        try {
            List<String> list = service.getAllPermissionsns();
            return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}
